<%--
  Created by IntelliJ IDEA.
  User: yxl
  Date: 2014/10/28
  Time: 16:31
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta name="layout" content="manage"/>
    <title>销售图片管理</title>
</head>

<body>
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            基础设置
        </li>
        <li class="active"><g:link controller="mngPhoto">销售图片管理</g:link></li>
    </ul><!-- .breadcrumb -->
    <div class="nav-search" id="nav-search">

    </div><!-- #nav-search -->
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            销售图片管理
            <small>
                <i class="icon-double-angle-right"></i>
                维护销售图片信息
            </small>
        </h1>
    </div><!-- /.page-header -->
    <div class="row">
        <div class="col-xs-12">
            <g:if test="${flash.message}">
                <div class="message alert alert-info">
                    <g:message message="${flash.message}"/>
                </div>
            </g:if>
        <!-- PAGE CONTENT BEGINS -->
            <table id="grid"></table>
            <div id="gridPager"/>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
<r:script>
        var gridSelector = "#grid";
        var gridPagerSelector = "#gridPager";
        var listUrl = "<g:createLink controller="mngPhoto" action="list" params="[format: 'json']"/>";
        function setStatus(id,state) {
            var queryData={
                "photoId":id,
                "state":state
            };
            $("#grid").jqGrid("setGridParam", { postData: queryData }).trigger("reloadGrid");
         }
         function setDisplay(id,statePlay) {
            var queryData={
                "display_photoId":id,
                "statePlay":statePlay
            };
            $("#grid").jqGrid("setGridParam", { postData: queryData }).trigger("reloadGrid");
         }
        jQuery(function($) {
            $(gridSelector).jqGrid({
                caption: "销售图像列表",
                url:  listUrl,
                 datatype: 'json',
                 colNames: [  "编码", "名称", "设备", "价格", "拍摄日期", "上传日期", "赞", "分享", "销售", "交易","上下架"," ","推荐"," "],
                 colModel: [
                    {name: 'id', index: 'id', width: 80,search: false},
                    { name: 'name', index: 'name', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'device', index: 'device', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'price',align:"right", index: 'price', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'picTime',align:"center", index: 'picTime', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        },
                        formatter:function(v){
                            var str1= v.replace(/Z/, "");
                            var str2 = str1.replace(/T/, " ");
                            return (str2);
                        }
                    },
                    { name: 'dateCreated',align:"center", index: 'dateCreated', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        },
                        formatter:function(v){
                            var str1= v.replace(/Z/, "");
                            var str2 = str1.replace(/T/, " ");
                            return (str2);
                        }
                    },
                    { name: 'laudNum', index: 'laudNum', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'shareNum', index: 'shareNum', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'saleNum', index: 'saleNum', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    { name: 'isDeal', index: 'isDeal',align:"center", width: 60,editoptions:{value:'1:是;0:否;'},
                         formatter:function(v){
                                    if(v==1){
                                         return"是";
                                    }else if(v==0){
                                         return"否";
                                    }
                                }
                     },
                     { name: 'display', index: 'display',align:"center", width: 60,editoptions:{value:'1:上架;0:下架;'},
                         formatter:function(p){
                                    return p ? '上架' : '<span style="color:green">下架</span>';
                                }
                     },
                     { name: 'display', index: 'display', align:"center", width: 80,editoptions:{value:'1:上架;0:下架;'},
                         formatter:function(p,a,b){
                              var statePlay = p?"0":"1";
                              var id=b.id;
                              var link="<a href='javascript:;' style='color:red;' onclick='setDisplay("+id+","+statePlay+")'>"+(statePlay=="0"?"下架":"上架")+"</a>";
                              return link;
                         }
                     },
                     { name: 'isRecommend', index: 'isRecommend',align:"center", width: 60,editoptions:{value:'1:推荐;0:不推荐;'},
                         formatter:function(v){
                                    return v ? '推荐' : '<span style="color:green">不推荐</span>';
                                }
                     },
                     { name: 'isRecommend', index: 'isRecommend', align:"center", width: 80,editoptions:{value:'1:推荐;0:不推荐;'},
                         formatter:function(v,a,b){
                              var state = v?"0":"1";
                              var id=b.id;
                              var link="<a href='javascript:;' style='color:red;' onclick='setStatus("+id+","+state+")'>"+(state=="0"?"取消推荐":"推荐")+"</a>";
                              return link;
                         }
                     }
                ],
                ondblClickRow: function(id) {
                    if (id) {
                        window.location.href="<g:createLink action='edit'/>?id=" + id;
                    }
                },
                viewrecords: true,
                pager: gridPagerSelector,
                autowidth: true,
                height: 'auto',
                rowNum: 25,
                recordtext: "从{0}到{1}共{2}",
                multiselect: true,
			    multiboxonly: true,
                jsonReader: {
                    root: 'datas',
                    page: 'page',
                    repeatitems : false
                }
            });
            $(gridSelector).jqGrid('filterToolbar',{
                autosearch: true,
                searchOnEnter: true,
                searchOperators: true,
                stringResult:true
            });
            $(gridSelector).jqGrid('navGrid',gridPagerSelector,
                { 	//navbar options
                    add: true,
                    addicon : 'icon-plus-sign purple',
                    addfunc: function() {
                        window.location.href="<g:createLink action='create'/>";
                    },
                    edit: true,
                    del: true,
                    refreshicon : 'icon-refresh green'
                },
                { //edit
                    recreateForm: true,
                    beforeInitData: function(form) {
                        var id = $(this).jqGrid('getGridParam','selrow');
                        window.location.href="<g:createLink action='edit'/>?id=" + id;
                        return false;
                    }
                },
                { //add
                },
                {   //delete
                    url: '<g:createLink action="delete" params="[format: 'json']"/>',
                    recreateForm: true,
                    beforeShowForm: function(form, oper) {
                        form.jqFormToken({
                            tokenUrl: '<g:createLink action="resetToken"/>'
                        });
                    },
                    afterSubmit: function(response, posted) {
                        var rs = $.parseJSON(response.responseText);
                        var results = [ rs["code"] == 0, rs["message"]];
                        if (results) {
                            $(gridSelector).setGridParam({url: listUrl }).trigger("reloadGrid");
                        }
                        return results;
                    }
                }
            );
            $(gridSelector).jqGrid ('navButtonAdd', gridPagerSelector,
                { caption: ""/*"Show"*/, buttonicon: "icon-search",
                  onClickButton: function() {
                       $(gridSelector)[0].triggerToolbar();
                  }
            });
        });
</r:script>
</body>
</html>